package com.huang825172.sbog;

import android.Manifest;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.graphics.Camera;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;

import com.camerakit.CameraKitView;
import com.huang825172.sbog.MainPage.View.MainActivity;
import com.huang825172.sbog.MainPage.View.MainPageFragmentAdapter;
import com.huang825172.sbog.Util.SystemUIControler;

import butterknife.BindView;
import butterknife.ButterKnife;
import pub.devrel.easypermissions.EasyPermissions;

public class SplashActivity extends AppCompatActivity {

    @BindView(R.id.splashActivity_splashGif)
    ImageView splashGif;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        ButterKnife.bind(this);

        GrantPermissions();

        //实现LOGO的淡出效果
        ObjectAnimator animator;
        animator = ObjectAnimator.ofFloat(splashGif, "alpha", 0f, 1f);
        animator.setDuration(1000);
        animator.start();

        //用于控制隐藏导航栏的Util类
        final SystemUIControler uiControler = new SystemUIControler(this);
        uiControler.hideSystemUI();

        //Splash页面停留三秒
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent();
                intent.setClass(SplashActivity.this, MainActivity.class);
                //intent.setClass(SplashActivity.this, BOSTest.class);
                uiControler.showSystemUI();
                startActivity(intent);
                finish();
            }
        }, 3000);
    }

    private void GrantPermissions() {
        String[] perms = {
                Manifest.permission.CAMERA,
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.READ_PHONE_STATE,
                Manifest.permission.ACCESS_WIFI_STATE,
                Manifest.permission.ACCESS_NETWORK_STATE
        };
        if (!EasyPermissions.hasPermissions(this, perms)) {
            EasyPermissions.requestPermissions(this, getString(R.string.needPermsHint), 0, perms);
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
    }
}
